﻿using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using ATSDAL;
using ATSModel;
using System.Collections.Generic;
using System.Web.Security;
using Microsoft.Office.Interop.Excel; 

 

/// <summary>
///ServiceForProductMOID_GetbySN 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
// [System.Web.Script.Services.ScriptService]
public class ServiceForPIMAndElec : System.Web.Services.WebService
{
    public THouse tHouse;
    public TMO tMo;
    public TProductType tProductType;
    public PIMTest pIMTest;
    public TMOIDConfig tMOIDConfig; 
    public TTest tTest; 
    public Role tRole;

    public AllStatusDal aStatus;

    public TRCUStatusCheck tRCUStatusCheck;
    public PrintRecordDal tPrintRecord;
    public ServiceForPIMAndElec()
    {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    } 

    [WebMethod(Description = "通过SN，获取SN对应的批号MOID")]
    public string ProductMOID_GetbySN(string ProductSN)
    { 
        tHouse = new THouse();
        return tHouse.ProductMOID_GetbySN(ProductSN).MOID;
    }


    [WebMethod(Description = "通过MOID，获取MOID对应的产品代码(S代码)")]
    public string ProductTypeID_GetbyMOID(string MOID)
    {
        tMo = new TMO();
        return tMo.ProductTypeID_GetbyMOID(MOID).ProductTypeID;
    }


    [WebMethod(Description = "通过S代码，获取S代码对应的产品类型名称")]
    public string ProductTypeName_GetbyProductTypeID(string ProductTypeID)
    {
        tProductType = new TProductType();
        return tProductType.ProductTypeName_GetbyProductTypeID(ProductTypeID).ProductTypeName;
    }


    [WebMethod(Description = "通过SN，获取SN对应交调最近时间成品OR成品返修测试结果及交调测试最差值")]
    public List<PIMTestInfo> PimResult_GetbySN(string ProductSN)
    {
        pIMTest = new PIMTest();
        return (List<PIMTestInfo>)pIMTest.PimResult_GetbySN(ProductSN);
    }


    [WebMethod(Description = "通过MOID，获取MOID对应交调特采数据集合")]
    public string PIMSpecail_GetbyMOID(string MOID)
    {
        tMOIDConfig = new TMOIDConfig();
        return tMOIDConfig.PIMSpecail_GetbyMOID(MOID).Settings;
    }


    [WebMethod(Description = "通过SN，获取SN对应电性能最近时间成品OR成品返修测试结果")]
    public string ElectricResult_GetbySN(string ProductSN)
    {
        tTest = new TTest();
        return tTest.ElectricResult_GetbySN(ProductSN).IsPass;
    }

    [WebMethod(Description = "通过SN，获取SN对应RCU检测结果")]
    public string RcuResult_GetbySN(string ProductSN)
    {
        tRCUStatusCheck = new TRCUStatusCheck();
        return tRCUStatusCheck.RcuResult_GetbySN(ProductSN).Status;
    }


    [WebMethod(Description = "用户登录账号验证")]
    public bool AuthenticateUser(string UserID, string Pwd)
    {
      
        TRoleInfo tInfo=new TRoleInfo();
        tRole = new Role();
        tInfo = tRole.GetForUser(UserID);

        if (tInfo == null)
        { 
            return false;
        }
        if (tInfo.Password == Pwd)
        {
          return true;
        } 
        return false;
    }

    [WebMethod(Description = "获取用户权限")]
    public string AuthenticateUser_ForPrintReform(string UserID)
    {
        TRoleInfo tInfo = new TRoleInfo();
        tRole = new Role();
        tInfo = tRole.GetForUser(UserID);
        return tInfo.Power;
    }


    [WebMethod(Description = "上传打印记录")]
    public bool Atenna_PrintData_Upload(PrintRecordInfo pi)
    { 
        tPrintRecord = new PrintRecordDal(); 
        if (pi == null) 
        {
            return false;
        } 
        if (tPrintRecord.PrintRecord_Insert(pi)) 
        {
            return true;
        }
        return false;
    }


    [WebMethod(Description = "通过ProductSN,下载SN对应打印记录集合")]
    public List<PrintRecordInfo> Atenna_PrintData_Download(string ProductSN)
    {
        tPrintRecord = new PrintRecordDal();
        return (List<PrintRecordInfo>)tPrintRecord.PrintRecord_GetbySN(ProductSN);
    }

    [WebMethod(Description = "通过ProductSN,获取测试状态")]
    public List<AllStatusInfo> EleResult_AllStatus_GetbySN(string ProductSN)
    {
        aStatus = new AllStatusDal();
        return (List<AllStatusInfo>)aStatus.EleResult_AllStatus_GetbySN(ProductSN);
    } 
}

